package com.cass.controller;


import com.cass.entity.StudentScore;
import com.cass.service.IStudentScoreService;
import com.cass.uilts.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生成绩 控制器
 * @Author: wangyou
 *
 */

@Slf4j
@RestController
@RequestMapping("/studentScore")
@RequiredArgsConstructor
@Tag(name = "StudentScoreController", description = "学生成绩")
public class StudentScoreController {
    private static final Logger logger = LoggerFactory.getLogger(StudentController.class);
    private final IStudentScoreService studentScoreService;

    /**
     * 获取所有学生成绩
     *
     */
    @Operation(summary = "获取学生成绩",description = "需要登录后访问")
    @ApiResponse(description = "返回获取学生成绩", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StudentScore.class)))
    @GetMapping()
    public Result<List<StudentScore>> getStudentScore(){
        logger.info("获取学生成绩");
        return Result.success(studentScoreService.list());

    }

    /**
     * 添加学生成绩
     *
     */
    @PostMapping()
    public Result<String> addStudentScore(@RequestBody StudentScore score){
        logger.info("添加学生成绩{}",score);
        studentScoreService.save(score);
        return Result.success("添加成功");
    }
    @DeleteMapping("/{id}")
    public Result<String> deleteStudentScore(@PathVariable Integer id){
        logger.info("删除学生成绩{}",id);
        studentScoreService.removeById(id);
        return Result.success("删除成功");
    }
    @PutMapping()
    public Result<String> updateStudentScore(@RequestBody StudentScore score){
        logger.info("修改学生成绩{}",score);
        studentScoreService.updateById(score);
        return Result.success("修改成功");
    }
    @GetMapping("/{id}")
    public Result<StudentScore> getStudentScoreById(@PathVariable Integer id){
        logger.info("获取学生成绩{}",id);
        return Result.success(studentScoreService.getById(id));
    }
    @DeleteMapping("/batchDelete")
    public Result<String> batchDelete(@RequestBody List<Integer> ids){
        logger.info("批量删除学生成绩{}",ids);
        studentScoreService.removeByIds(ids);
        return Result.success("批量删除成功");
    }
}
